
public class distancecalc2 {

	public static void main(String args[]){
		
		double lat1 = 40.44699;
		double lng1 =  -79.94819;
		double lat2 = 40.44442;
		double lng2 = -79.942984;
		
		
	double distance = distance(lat1,lng1,lat2,lng2);
	System.out.println("distance = "+distance+" km");
	
		
	}
	
	
	private static double distance(double lat1, double lng1, double lat2, double lng2) {
		  double theta = lng1 - lng2;
		  double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
		  dist = Math.acos(dist);
		  dist = rad2deg(dist);
		  dist = dist * 60 * 1.1515;
		  
		    dist = dist * 1.609344; 					// to calculate distance in kilo meters
		  
		  return (dist);
		}

		/*-------------------------------------------*/
		/* function to convert degrees to radians   */
		/*-----------------------------------------*/
	
		private static double deg2rad(double deg) {
		  return (deg * Math.PI / 180.0);
		}

		/*-------------------------------------------*/
		/* function to convert radians to degrees   */
		/*-----------------------------------------*/
		
		private static double rad2deg(double rad) {
		  return (rad * 180.0 / Math.PI);
		}

	
}
